package cn.monkey.io.transport.netty.server.codec.protocol;

import io.netty.channel.Channel;

import java.util.function.BiPredicate;
import java.util.function.Consumer;

public abstract class AbstractServerProtocolRouterFunction implements ServerProtocolRouterFunction {

    protected final BiPredicate<Channel, Object> predicate;

    protected final Consumer<Channel> consumer;

    public AbstractServerProtocolRouterFunction(BiPredicate<Channel, Object> predicate, Consumer<Channel> consumer) {
        this.predicate = predicate;
        this.consumer = consumer;
    }

    @Override
    public boolean test(Channel channel, Object data) {
        return this.predicate.test(channel, data);
    }

    @Override
    public void accept(Channel channel) {
        this.consumer.accept(channel);
    }
}
